package main.java.com.lee.pattern.masterworker;

import java.util.stream.IntStream;

/**
 * @Description TODO
 * @Author winston
 * @DateTime 2022/2/18
 */
public class MasterWorkerTest {
    static class SimpleTask extends Task<Integer> {
        @Override
        protected Integer doExecuted() {
            System.out.println("task " + getTaskId() + " is done");
            int sum = 0;
            for (int i = 1; i <= 1000000; i++) {
                sum += i;
            }
            System.out.println(sum);
            return sum;
        }
    }

    public static void main(String[] args) throws InterruptedException {
        Master<SimpleTask, Integer> master = new Master<>(4);
        master.submit(new SimpleTask());
        master.submit(new SimpleTask());
        master.submit(new SimpleTask());
        master.submit(new SimpleTask());
//        Thread.sleep(3000);
        master.printResult();
        master.stop();
    }
}
